<?php
/**
 * Created by JetBrains PhpStorm.
 * User: q
 * Date: 14-1-13
 * Time: 上午10:42
 * To change this template use File | Settings | File Templates.
 */
class Event_model extends CI_Model{
    function __construct(){
        parent::__construct();
    }
    function insert($data){
        $this->db->insert('school', $data);
    }
    /*
     * 保存照片入口
     */
    function setEvent($data,$id_class){
//        var_dump($data);
        $id = $this->savePhoto($data['path'],$id_class,$data['event_time']);
        $this->saveEvent($data,$id);
    }
    /*
     * 保存评价入口
     */
    function setContent($data,$id_class){
        $id = $this->saveNote($data['content'],$id_class,count($data['students']),$data['event_time']);
        $this->saveContent($data,$id);
    }

    /*
     * 照片入库
     */
    function savePhoto($path,$id_class,$photo_time){
        $in['path'] = $path;
        $in['id_class'] = $id_class;
        $in['update_time'] = $photo_time;
        $qy = $this->db->insert('photos',$in);
        $id = $this->db->insert_id();
        return $id;
    }

    /*
     * 将照片分发给学生
     */
    function saveEvent($data,$id){
        foreach($data['students'] as $key => $val){
            $info[] = array(
                'id_student' => $val,
                'event_time' => $data['event_time'],
                'id_photo' => $id
            );
        }



        $this->db->insert_batch('event', $info);
    }

    /*
     * 评价入库
     */
    function saveNote($path,$id_class,$count,$content_time){
        $in['content'] = $path;
        $in['id_class'] = $id_class;
        $in['count'] = $count;
        $in['content_time'] = $content_time;
        $qy = $this->db->insert('content',$in);
        $id = $this->db->insert_id();
        return $id;
    }

    /*将评价分发给学生
     *
     */
    function saveContent($data,$id){
        foreach($data['students'] as $key => $val){
            $info[] = array(
                'id_student' => $val,
                'event_time' => $data['event_time'],
                'id_content' => $id
            );
        }

//        var_dump($info);

        $this->db->insert_batch('event', $info);
    }

}